package org.example.controller;

import org.example.domain.entity.ProductComments;
import org.example.model.Result;
import org.example.service.ProductCommentsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/com")
@CrossOrigin("*")
public class ProductCommentsController {
    @Resource
    private ProductCommentsService commentsService;
    @GetMapping("/query")
    public Result queryImgById(@RequestParam Integer productId){
        return Result.buildSuccess(commentsService.queryComments(productId));
    }
    @PostMapping("/update")
    public Result updateImg(@RequestBody ProductComments com){
        Boolean b = commentsService.updateComment(com);
        if(b){
            return Result.buildSuccess(null);
        }else{
            return Result.buildFail("修改失败");
        }
    }
    @GetMapping("/delete")
    public Result deleteImg(@RequestParam Integer comId){
        Boolean b = commentsService.deleteComment(comId);
        if(b){
            return Result.buildSuccess(null);
        }else{
            return Result.buildFail("删除失败");
        }
    }
    @PostMapping("/insert")
    public Result insertImg(@RequestBody ProductComments com){
        Boolean b = commentsService.insertComment(com);
        if(b){
            return Result.buildSuccess(null);
        }else{
            return Result.buildFail("新增评论失败");
        }
    }
}
